<?php

class Application_Form_Search extends Zend_Form
{
	public function __construct($options = null)
	{
		parent::__construct($options);
		$this->setName('search');
		$this->setMethod("post");
		

			
		$keyword = new Zend_Form_Element_Text('keyword');
		$keyword->setAttrib('placeholder', 'Keywords...');
		$keyword->setAttrib('class', 'span8');
		$keyword->setRequired(true);
		$keyword->setFilters(array('StringTrim','StripTags'));
		
		$admin_area_lvl1 = new Zend_Form_Element_Hidden('admin_area_lvl1');
		$admin_area_lvl1->setAttrib('placeholder', 'region');
		$admin_area_lvl1->setAttribs(array('class' => 'span2'));
		$admin_area_lvl1->setFilters(array('StringTrim','StripTags'));
		
		$admin_area_lvl2 = new Zend_Form_Element_Hidden('admin_area_lvl2');
		$admin_area_lvl2->setAttrib('placeholder', 'department');
		$admin_area_lvl2->setAttribs(array('class' => 'span2'));
		$admin_area_lvl2->setFilters(array('StringTrim','StripTags'));
		
		$country = new Zend_Form_Element_Hidden('country');
		$country->setAttrib('placeholder', 'country');
		$country->setAttribs(array('class' => 'span2'));
		$country->setFilters(array('StringTrim','StripTags'));
		
		$offerClass = new Zend_Form_Element_Hidden('class');
		$offerClass->setAttrib('placeholder', 'class');
		$offerClass->setAttribs(array('class' => 'span2'));
		$offerClass->setFilters(array('StringTrim','StripTags'));
		
		$price_min = new Zend_Form_Element_Text('pricemin');
		$price_min->setAttrib('placeholder', 'price min')
		->setFilters(array('StringTrim','StripTags'))
		->addValidator('float', true, array('locale' => 'en_US'));
		
		$price_max = new Zend_Form_Element_Text('pricemax');
		$price_max->setAttrib('placeholder', 'price max')
		->setFilters(array('StringTrim','StripTags'))
		->addValidator('float', true, array('locale' => 'en_US'));
		
		$yearCond = array('min' => 1900, 'max' => date('Y'));
		$cyear = array_combine(range(date('Y'),1900,-1), range(date('Y'),1900,-1));
		//Year Field
		$year_min = new Zend_Form_Element_Select('yearmin');
		$year_min->addMultiOptions(array('0' => 'Year min:')+$cyear);
		
		
		$year_max = new Zend_Form_Element_Select('yearmax');
		$year_max->addMultiOptions(array('0' => 'Year max:')+$cyear);
		
		$energyChoice = array('1' => 'Diesel', '2' => 'Essence');
		$energy = new Zend_Form_Element_Select('energy');
		$energy->addMultiOptions(array('0' => 'Choice:')+$energyChoice);
		$energy->class = 'energy';
		
		$transmissionChoice = array('1' => 'Manual', '2' => 'Automatic');
		$transmission = new Zend_Form_Element_Select('transmission');
		$transmission->addMultiOptions(array('0' => 'Choice:')+$transmissionChoice);
		$transmission->class = 'transmission';
		
		$mileageCond = array('min' => 0, 'max' => 250000);
		$cmileageformin = array_combine(range(0,100000,10000), range(0,100000,10000));
		$cmileageformax = array_combine(range(10000,100000,10000), range(10000,100000,10000));
		$cmileage2 = array_combine(range(125000,300000,25000), range(125000,300000,25000));
		
		$mileage_min = new Zend_Form_Element_Select('mileagemin');
		$mileage_min->addMultiOptions(array('0' => 'mileage min:')+$cmileageformin+$cmileage2);
		
		$mileage_max = new Zend_Form_Element_Select('mileagemax');
		$mileage_max->addMultiOptions(array('0' => 'mileage max:')+$cmileageformax+$cmileage2+array('999999' => 'more then 300000'));
		
		$cylinder0 = array(0,50,80,125,250,500,600,750,1000);
		$cylinder = array(50,80,125,250,500,600,750,1000);
		$ccylinderformin = array_combine($cylinder0, $cylinder0);
		$ccylinderformax = array_combine($cylinder, $cylinder);
		
		$cylinder_min = new Zend_Form_Element_Select('cylindermin');
		$cylinder_min->addMultiOptions(array('0' => 'cylinder min:')+$ccylinderformin);
		
		$cylinder_max = new Zend_Form_Element_Select('cylindermax');
		$cylinder_max->addMultiOptions(array('0' => 'cylinder max:')+$ccylinderformax+array('999999' => 'more then 1000'));
		
		$surfaceformin = array_combine(range(0,300,10), range(0,300,10));
		$surfaceformax = array_combine(range(10,300,10), range(10,300,10));
		
		$surface_min = new Zend_Form_Element_Select('surfacemin');
		$surface_min->addMultiOptions(array('0' => 'surface min:')+$surfaceformin);
		
		$surface_max = new Zend_Form_Element_Select('surfacemax');
		$surface_max->addMultiOptions(array('0' => 'surface max:')+$surfaceformax+array('999999' => 'more then 300'));
		
		$objects = array('object','car','motorcycle','house','apartment','desktop','laptop','phone','TV','clothing','book','other');
		$cobjects = array_combine($objects, $objects);
		$objectselect = new Zend_Form_Element_Select('objectselect');
		$objectselect->addMultiOptions($cobjects);
		$objectselect->setAttrib('class', 'span1');
		$objectselect->setAttrib('id', 'select');
		
		$submit = new Zend_Form_Element_Submit('submit');
		$submit->setAttrib('id', 'submitbutton')
		->setLabel('save');



		$elements = array($keyword,$admin_area_lvl1,$admin_area_lvl2,$country,$offerClass,$price_min,$price_max,$year_min,$year_max,
				$surface_max,$surface_min,$cylinder_max,$cylinder_min,
				$mileage_max,$mileage_min,$energy,$transmission,
				$objectselect,$submit);
		$this->addElements($elements);

		$this->setDecorators( array( array('ViewScript', array('viewScript' => 'forms/search.phtml'))));
	}
}